<SCRIPT language=Javascript>
    function isNumberKey(evt){
        var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;
        return true;
    }
</SCRIPT>

<?php
	include './pages/adminMenu.php';
	include('./system/dbConnection.php');
	if(isset($_SESSION['userTypeId'])){
		$typeId = $_SESSION['userTypeId']; 
	}
	if($result=mysql_query("SELECT * FROM users, user_types WHERE users.userTypeId = user_types.typeId AND userTypeId > $typeId" )){
		$num = mysql_num_rows($result);
	}else{
		$_SESSION['error'] = 'Error Occured!';
	}
?>
	
<div class="mainContent">
	<h3>Users<h3>
	<table border="1px" width="90%" align="center">
				<?php
				if(isset($_SESSION['error']) && $_SESSION['error'] != ""){ ?>
					<div class="error">
						<?php echo $_SESSION['error']; ?>
					</div>
				<?php } else if(isset($_SESSION['success']) && $_SESSION['success'] != ""){?>
					<div class="success">
						<?php echo $_SESSION['success']; ?>
					</div>
				<?php }?>		
		<tr>
			<th>User name</th>
			<th>Full name</th>
			<th>Password</th>
			<th>Address</th>
			<th>Tele No</th>
			<th>User Type</th>
			<th>Status</th>
			<th>Save Data</th>
		</tr>
	<?php
		$i=0;
		while ($i < $num) {
			$f1=mysql_result($result,$i,"userName");
			$f2=mysql_result($result,$i,"userFullName");
			$f3=mysql_result($result,$i,"userAddress");
			$f4=mysql_result($result,$i,"userTelephone");
			$f5=mysql_result($result,$i,"userTypeId");
			$f6=mysql_result($result,$i,"status");
	?>
			<tr>
				<form id="editData" method="post" action="./system/action/editUsers.php">
					<td><input type="hidden" name="user" value="<?php echo $f1?>" /><?php echo $f1?></td>
					<td><input type="text" name="userFullName" value="<?php echo $f2?>" /></td>
					<td>change<input type="checkbox" name="checkbox" value="yes" class="checkbox" /></td>
					<td><input type="text" name="userAddress" value="<?php echo $f3?>"/></td>
					<td><input type="text" id="userTelephone" name="userTelephone" value="<?php echo $f4?>" onkeypress="return isNumberKey(event)" size="10"/></td>
					<td><select name="userTypeId" id="userTypeId">
						<?php if($res = mysql_query("SELECT * FROM user_types WHERE typeId > $typeId")){
								while($row2 = mysql_fetch_assoc($res)){
									if($row2['typeId'] == $f5)
										echo "<option selected='selected' value='".$row2['typeId']."'>".$row2['typeName']."</option>";
									else
										echo "<option value='".$row2['typeId']."'>".$row2['typeName']."</option>";
								}
							}?>
						</select>
					</td>
					<td><select name="status"/>
							<option selected="selected" value="<?php echo $f6?>"><?php echo $f6?></option>
							<option value="<?php if($f6=="ACTIVE") echo "INACTIVE";else echo "ACTIVE"?>"><?php if($f6=="ACTIVE") echo "INACTIVE";else echo "ACTIVE"?></option>
						</select>
					</td>
					<td align="center"><input type="submit" name="Submit" value="Save" style="width:60px"/></td>
				</form>
			</tr>
	<?php
			$i++;
		}
	?>
	</table>
</div>